package com.situ.firmadmin.config;

import com.situ.firmadmin.converter.String2DateConverter;
import com.situ.firmadmin.interceptor.LoginInterceptor;
import com.situ.firmadmin.pojo.User;
import com.situ.firmadmin.service.IAuthService;
import com.situ.firmadmin.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private IUserService userService;
    @Autowired
    private IAuthService authService;

    @Bean
    public User createUser(){
        return new User();
    }

    //日期转换
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new String2DateConverter() );
    }

    //配置虚拟路径【图片】
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**")
                .addResourceLocations("file:/D:/zhongxiangsitu/mypic/blog/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")  //拦截所有
                .excludePathPatterns("/page/login","/user/login","/user/logout","/static/**","/captcha","/getVerifyCode");       //放行
    }

}
